package com.lagou.client;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

public class CuratorClient {

    public static String path = "/netty-provider";

    public static CuratorFramework curatorClient;

    public static CuratorFramework getCuratorClient(){
        if (curatorClient == null){
            RetryPolicy exponentialBackoffRetry = new ExponentialBackoffRetry(1000, 3);
            //使用fluent变成风格
            curatorClient = CuratorFrameworkFactory.builder()
                    .connectString("192.168.228.130:2181") //server地址
                    .sessionTimeoutMs(50000) // 会话超时时间
                    .connectionTimeoutMs(30000) // 连接超时时间
                    .retryPolicy(exponentialBackoffRetry) // 重试策略
                    .namespace("base") // ⽴命名空间/base
                    .build(); //
            curatorClient.start();
        }
        return curatorClient;
    }

}
